package com.example.planetandzombiedemo.entity;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.MotionEvent;

import com.example.planetandzombiedemo.global.Config;
import com.example.planetandzombiedemo.model.BaseModel;
import com.example.planetandzombiedemo.model.Touchable;
import com.example.planetandzombiedemo.view.GameView;

public class SeedPea extends BaseModel implements Touchable {
    //触摸区域(卡片范围内)
    private Rect touchArea;

    public SeedPea(int locationX, int locationY) {
        this.locationX = locationX;
        this.locationY = locationY;
        this.isAlife = true;
        touchArea = new Rect(locationX, locationY,
                locationX + Config.seedPea.getWidth(), locationY + Config.seedPea.getHeight());
    }

    @Override
    public void drawSelf(Canvas canvas, Paint paint) {
        if (isAlife) {
            canvas.drawBitmap(Config.seedPea,locationX,locationY,paint);
        }
    }

    @Override
    public int getModelWidth() {
        return Config.seedPea.getWidth();
    }

    @Override
    public boolean onTouch(MotionEvent event) {
        int x=(int)event.getRawX();
        int y=(int)event.getRawY();
        if(touchArea.contains(x,y))//触摸点在Pea卡片区域内
        {
            //豌豆射手值：pea-100
            if(Config.sunLight>=100){
                apply4EmplaceFlower();
                return true;
            }
        }
        return false;
    }

    private void apply4EmplaceFlower() {
        GameView.getInstance().apply4EmplacePlant(locationX,locationY,this);
    }
}